package fr.inserm.u915.organifooyi.model;

import javax.persistence.*;
import javax.servlet.*;
 
public class MainListener implements ServletContextListener
	{
    // Prepare the EntityManagerFactory & Enhance:
    public void contextInitialized(ServletContextEvent e) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("organifooyidao");
        e.getServletContext().setAttribute("emf", emf);
    	}
 
    // Release the EntityManagerFactory:
    public void contextDestroyed(ServletContextEvent e)
    	{
        EntityManagerFactory emf =
            (EntityManagerFactory)e.getServletContext().getAttribute("emf");
        if(emf!=null && emf.isOpen()) emf.close();
	    }
	}